package cn.cleanarch.infra.idp.pms.config;

import org.springframework.context.annotation.Configuration;
import jakarta.annotation.PostConstruct;

/**
 * Liquibase配置类
 * 解决XSD解析问题
 * 通过系统属性配置来禁用安全XML解析
 */
@Configuration
public class LiquibaseConfig {

    @PostConstruct
    public void init() {
        // 在最早的时候设置系统属性
        setSystemProperties();
    }

    private void setSystemProperties() {
        // 设置系统属性禁用安全XML解析
        System.setProperty("liquibase.secureParsing", "false");
        System.setProperty("liquibase.xsd.allowRemote", "true");
        System.setProperty("liquibase.xmlValidation", "false");
        System.setProperty("liquibase.skipXmlValidation", "true");
        System.setProperty("liquibase.xsd.classpath.search", "false");
        
        System.out.println("=== Liquibase配置初始化 ===");
        System.out.println("- liquibase.secureParsing: " + System.getProperty("liquibase.secureParsing"));
        System.out.println("- liquibase.xsd.allowRemote: " + System.getProperty("liquibase.xsd.allowRemote"));
        System.out.println("- liquibase.xmlValidation: " + System.getProperty("liquibase.xmlValidation"));
        System.out.println("- liquibase.skipXmlValidation: " + System.getProperty("liquibase.skipXmlValidation"));
        System.out.println("- liquibase.xsd.classpath.search: " + System.getProperty("liquibase.xsd.classpath.search"));
        System.out.println("=== 配置完成 ===");
    }
}